import { View } from "../../../../mvc/core/View";
import { LayerManager } from "../../../manager/LayerManager";
import { Global } from "../../../../../com/gengine/global/Global";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { ImageInfo } from "../../../../../com/gengine/resource/info/ImageInfo";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { SecTimerView } from "../../common/SecTimerView";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { LongProgressBar } from "../../player/LongProgressBar";
import { SGuildPartyOpen } from "../../../../../Message/Game/SGuildPartyOpen";
import { GuildUtil } from "../info/GuildUtil";
import { ClockManager } from "../../../manager/ClockManager";
import { Cache } from "../../../cache/Cache";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { ShopRule } from "../../../rules/ShopRule";
import { NormalShopType } from "../../shop/info/NormalShopType";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { SundryShop } from "../../../../../ShopRule/SundryShop";
import { DefaultShop } from "../../../../../NormalShopType/DefaultShop";
type int = number;
//class GuildPartyResultPanel
    
    export  class GuildPartyResultPanel extends View
    {
        constructor()
        {
            super();
            this.layer = LayerManager.uiLayer;
            this.init();
            this.x = Global.stage.stageWidth - 500;
            this.y = 90;
            return;
        }

        /* internal  */init(): void
        {
            var textFormat: Object /* flash.text.TextFormat */;

            var loc1;
            this._buyBtn = ObjCreate.createGButton(Language.getString(57437), 40, 2, 110, 22, this, "GuildPartyTimeBtn");
            this._buyBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBuyBtnClickHandler);
            this._buyBtn.toolTipData = Language.getString(57488);
            this._moveBtn = ObjCreate.createGButton("", 150, 2, 24, 22, this, "MoveBtn");
            this._moveBtn.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMouseDownHandler);
            this._moveBtn.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onMouseUpHandler);
            this._bitmap = new Object /* flash.display.Bitmap */();
            this._bitmap.x = -30;
            this.addChild(this._bitmap);
            LoaderManager.instance.load("GuildPartyMood.png", (arg1: ImageInfo): void
            {
                _bitmap.bitmapData = arg1.bitmapData;
                return;
            })
            ObjCreate.createBg(40, 23, 135, 85, this, ImagesConst.WindowCenterA);
            this._nameTxt = ObjCreate.createTextField("", 45, 28, 220, 20, this, new GTextFormat(FontUtil.songtiName, 12, 65280));
            this._leftTimeView = new SecTimerView();
            this._leftTimeView.mouseEnabled = false;
            textFormat = new GTextFormat(FontUtil.songtiName, 12, 16580352);
            textFormat.align = flash.text.TextFormatAlign.CENTER;
            this._leftTimeView.defaultTextFormat = new GTextFormat(FontUtil.songtiName, 12, 16742658, true);
            this._leftTimeView.filters = [FilterConst.glowFilter];
            this._leftTimeView.setParse("hh: mm: ss");
            ObjCreate.setObjAttri(this._leftTimeView, 105, 28, 100, 20, this);
            ObjCreate.createTextField(Language.getString(57438), 45, 48, 220, 20, this, GlobalStyle.textFormat6);
            this._expTxt = ObjCreate.createTextField("0", 105, 48, 220, 20, this, new GTextFormat(FontUtil.songtiName, 12, 16742658));
            ObjCreate.createTextField(Language.getString(57477), 45, 68, 220, 20, this, GlobalStyle.textFormat6);
            this._auraTxt = ObjCreate.createTextField("0", 105, 68, 220, 20, this, new GTextFormat(FontUtil.songtiName, 12, 16742658));
            ObjCreate.createTextField(Language.getString(57609), 45, 88, 220, 20, this, GlobalStyle.textFormat6);
            this._contriTxt = ObjCreate.createTextField("0", 105, 88, 220, 20, this, new GTextFormat(FontUtil.songtiName, 12, 16742658));
            ObjCreate.createTextField(Language.getString(57472), -10, 107, 220, 20, this, GlobalStyle.textFormat6);
            this._moodBar = new LongProgressBar();
            this._moodBar.setBgSize(135, 14);
            this._moodBar.progressBarClass = ImagesConst.EnergyBar;
            this._moodBar.move(40, 107);
            this._moodBar.setValue(0, this._maxMood);
            this._moodBar.toolTipData = Language.getString(57457);
            this.addChild(this._moodBar);
            return;
        }

        public updateByGuildPartyOpen(arg1: SGuildPartyOpen): void
        {
            var loc1=0;
            var loc2=null;
            var loc3=null;
            if (arg1) 
            {
                this._nameTxt.htmlText = GuildUtil.getGuildPartyTypeName(arg1.type.__value);
                loc2 = arg1.endDt;
                loc3 = ClockManager.instance.nowDate;
                loc1 = (loc2.time - loc3.time) / 1000;
                if (loc1 >= 0) 
                {
                    this._leftTimeView.setLeftTime(loc1);
                }
            }
            return;
        }

        public updateExp(arg1: number): void
        {
            this._expTxt.text = arg1.toString();
            return;
        }

        public updateAura(arg1: number): void
        {
            this._auraTxt.text = arg1.toString();
            return;
        }

        public updateMood(arg1: int): void
        {
            this._moodBar.setValue(arg1, this._maxMood);
            return;
        }

        public updateContri(arg1: int): void
        {
            this._contriTxt.text = arg1.toString();
            return;
        }

        /* internal  */onBuyBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var e: Object /* flash.events.Event */;
            var amount: int;
            var items: Array<any>;
            var onBtnClickHandler: Function;

            var loc1;
            amount = 0;
            e = arg1;
            items = Cache.instance.pack.backPackCache.getItemsByJudge(ItemsUtil.isGuildPartyHot);
            amount = items.length;
            if (amount > 0) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_Use, items[0]));
            }
            else 
            {
                onBtnClickHandler = (arg1: int): void
                {
                    if (arg1 == Alert.OK) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.ShopOpen, {"shopCode": SundryShop, "shopType": DefaultShop}));
                        Alert.resetToDefault();
                    }
                    return;
                }
                Alert.show(Language.getString(57487), null, Alert.OK | Alert.CANCEL, null, onBtnClickHandler);
            }
            return;
        }

        /* internal  */onMouseDownHandler(arg1: Object /* flash.events.Event */): void
        {
            this.startDrag();
            return;
        }

        /* internal  */onMouseUpHandler(arg1: Object /* flash.events.Event */): void
        {
            this.stopDrag();
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            if (Cache.instance.guild.partyHot) 
            {
                this.updateMood(Cache.instance.guild.partyHot.degree);
            }
            return;
        }

        /* internal */ /* var */_bitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_buyBtn: GButton;

        /* internal */ /* var */_moveBtn: GButton;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_leftTimeView: SecTimerView;

        /* internal */ /* var */_expTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_auraTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_contriTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_moodBar: LongProgressBar;

        /* internal */ /* var */_maxMood: int=1000;

        /* internal */ /* var */_totalExp: number=0;
    }
